package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.LastUserListenPlayVo;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @author Petrichor
 */
@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

	private final UserListenProcessService userListenProcessService;
	@Autowired
	public UserListenProcessApiController(UserListenProcessService userListenProcessService) {
		this.userListenProcessService = userListenProcessService;
	}
	/**
	 * @description: 获取声音播放进度
	 * @author Petrichor
	 * @date 2024/1/1 16:59
	 * @param trackId 声音id
	 * @return 该声音id 运行的秒伤
	**/
	@GuiGuLogin
	@Operation(summary = "获取声音的上次跳出时间")
	@GetMapping("/getTrackBreakSecond/{trackId}")
	public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId) {
		Long userId = AuthContextHolder.getUserId();
		BigDecimal trackBreakSecond = userListenProcessService.getTrackBreakSecond(userId, trackId);
		return Result.ok(trackBreakSecond);
	}
	/**
	 * @description: 更新播放进度
	 * @author Petrichor
	 * @date 2024/1/1 15:59
	 * @param userListenProcessVo 专辑id 声音id 音频播放位置
	 **/
	@GuiGuLogin
	@Operation(summary = "更新播放进度")
	@PostMapping("/updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo) {
		Long userId = AuthContextHolder.getUserId();
		userListenProcessService.updateListenProcess(userId, userListenProcessVo);
		return Result.ok();
	}
	/**
	 * @description: 获取最近一次播放声音
	 * @author Petrichor
	 * @date 2024/1/2 20:14
	 * @return LastUserListenPlayVo 专辑id 声音id
	**/
	@GuiGuLogin
	@Operation(summary = "获取最近一次播放声音")
	@GetMapping("/getLatelyTrack")
	public Result<LastUserListenPlayVo> getLatelyTrack() {
		Long userId = AuthContextHolder.getUserId();
		LastUserListenPlayVo lastUserListenPlayVo = userListenProcessService.getLatelyTrack(userId);
		return Result.ok(lastUserListenPlayVo);
	}
}

